#!/bin/bash

# 构建AAR脚本
# 使用方法: ./build-aar.sh

echo "开始构建Robot Manager AAR..."

# 备份原始build.gradle.kts
cp app/build.gradle.kts app/build.gradle.kts.backup

# 使用library版本的构建配置
cp app/build-library.gradle.kts app/build.gradle.kts

# 清理之前的构建
./gradlew clean

# 构建AAR
./gradlew assembleRelease

# 恢复原始build.gradle.kts
mv app/build.gradle.kts.backup app/build.gradle.kts

# 查找生成的AAR文件
AAR_FILE=$(find app/build/outputs/aar -name "*.aar" | head -1)

if [ -f "$AAR_FILE" ]; then
    echo "AAR构建成功: $AAR_FILE"
    
    # 复制到根目录
    cp "$AAR_FILE" ./robot-manager.aar
    echo "AAR已复制到根目录: robot-manager.aar"
    
    # 显示文件信息
    echo "文件信息:"
    ls -lh robot-manager.aar
    
    # 创建版本信息
    echo "Robot Manager SDK" > robot-manager-version.txt
    echo "Version: 1.0" >> robot-manager-version.txt
    echo "Build Date: $(date)" >> robot-manager-version.txt
    echo "Target SDK: 36" >> robot-manager-version.txt
    echo "Min SDK: 24" >> robot-manager-version.txt
    
    echo "版本信息已保存到: robot-manager-version.txt"
else
    echo "AAR构建失败！"
    exit 1
fi

echo "构建完成！"
